﻿using System;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Cms.Web.Framework.Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cms.Tests.Unit.WebFramework.Infrastructure
{
    [TestClass]
    public class ImageResizerTests
    {
        [TestMethod]
        public void CalculateNewSize_MaxSizeIsBiggerThanOriginal_KeepOriginal()
        {
            Size originalSize = new Size(400, 90);
            Size maxSize = new Size(500, 250);
            Size newSize = ImageResizer.CalculateNewSize(originalSize, maxSize);
            Assert.AreEqual(newSize.Width, originalSize.Width);
            Assert.AreEqual(newSize.Height, originalSize.Height);
        }

        [TestMethod]
        public void CalculateNewSize_OriginalIsLandscapeFormat_ScaleByWidth()
        {
            Size originalSize = new Size(400, 200);
            Size maxSize = new Size(100, 100);
            Size newSize = ImageResizer.CalculateNewSize(originalSize, maxSize);
            Assert.AreEqual(100, newSize.Width);
            Assert.AreEqual(50, newSize.Height);
        }

        [TestMethod]
        public void CalculateNewSize_OriginalIsPortraitFormat_ScaleByHeight()
        {
            Size originalSize = new Size(200, 400);
            Size maxSize = new Size(100, 100);
            Size newSize = ImageResizer.CalculateNewSize(originalSize, maxSize);
            Assert.AreEqual(50, newSize.Width);
            Assert.AreEqual(100, newSize.Height);
        }

        [TestMethod]
        public void CalculateNewSize_CheckRounding_CorrectNewSize()
        {
            Size originalSize = new Size(314, 137);
            Size maxSize = new Size(88, 45);
            Size newSize = ImageResizer.CalculateNewSize(originalSize, maxSize);
            Assert.AreEqual(88, newSize.Width);
            Assert.AreEqual(38, newSize.Height);
        }
    }
}
